<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该问卷，请重新选择！','error','jy_wenjstar/myhome/');
	}
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	pdo_update('jy_wenjstar_list',array('readnum +='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$item=pdo_get('jy_wenjstar_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$this->session('dati_id',$_RQ['id']);
	$post=pdo_get('jy_wenjstar_log',array('issub'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'datiid'=>$_RQ['id']));
	if($post['id']){
		$post['content']=json_decode($post['content'],true);
		$post['diyformfields']=json_decode($post['diyformfields'],true);
	}else{
		$post['datiid']=$item['id'];
		$post['content']=$this->model('diaocha')->gettikus($item);
		$post['diyformfields']=json_decode($item['diyformfields'],true);
	}
	$post['content']=array_values($post['content']);
	foreach($post['content'] as &$v){
		$v['typetitle']=$this->ti_types[$v['type']];
	}
	$return['allnum']=count($return['post']['content']);
	$return['item']=$item;
	$return['banner']=json_decode($item['hdp'],true);
	$post['name']=$post['name']?:$member['nickname'];
	$return['post']=$post;
	$return['member']=$member;
	$return['danan_key']=$this->danan_key;
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['desc'],
		'link'=>custom_url('jy_wenjstar/diaocha//id='.$item['id'],true),
		'imgUrl'=>tomedia($item['image']),
	);
	set_html('title',$item['title']);
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['name']){
		exi('请先提交！客户姓名','error');
	}
	$insert=array(
		'issub'=>1,
		'name'=>$postdata['name'],
		'dayid'=>date('Y-m-d',TIMESTAMP),
		'diyformfields'=>ijson_encode($postdata['diyformfields']),
		'content'=>ijson_encode($postdata['content']),
	);
	if($postdata['id']){
		pdo_update('jy_wenjstar_log',$insert,array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['id']));
	}else{
		$insert['uniacid']=$_SESSION['uniacid'];
		$insert['mid']=$_SESSION['uid'];
		$insert['datiid']=$postdata['datiid'];
		$insert['status']=1;
		$insert['createtime']=TIMESTAMP;
		pdo_insert('jy_wenjstar_log',$insert);
	}
	exi('提交问卷成功','','jy_wenjstar/myhome/');
}